package com.wwz.leetcode;


/**
 * 买卖股票的最佳时机 I
 */
public class SwordFinger63 {

    public static void main(String[] args) {
        int prices[] = {7,1,5,3,6,4};
        int i = maxProfit(prices);
        System.out.println(i);
    }

        public static int maxProfit(int[] prices) {
            int cost = Integer.MAX_VALUE, profit = 0;
            for(int price : prices) {
                cost = Math.min(cost, price);  //拿最低的价格
                profit = Math.max(profit, price - cost);//有最高的利润
            }
            return profit;
        }



}
